<?PHP
 session_start();
 include("admin/include/db.php");
 include("includes/session.php");
 
 $userId = $_SESSION['user_id'];
 
 
 if(isset($_REQUEST) && $_REQUEST['submit'] != ''){
 	
	$user_type 		= mysql_real_escape_string($_REQUEST['user_type']); 
	$user_course	= $_REQUEST['user_course'];

	$first_name 	= mysql_real_escape_string($_REQUEST['first_name']);
	$last_name 		= mysql_real_escape_string($_REQUEST['last_name']);
	$user_mobile 	= mysql_real_escape_string($_REQUEST['user_mobile']);
	$user_address 	= mysql_real_escape_string($_REQUEST['user_address']);
	$user_city 		= mysql_real_escape_string($_REQUEST['user_city']);
	$user_state 	= mysql_real_escape_string($_REQUEST['user_state']);
	$user_country 	= mysql_real_escape_string($_REQUEST['user_country']);
	$user_comments 	= mysql_real_escape_string($_REQUEST['user_comments']);
	$active 		= mysql_real_escape_string($_REQUEST['active']);
	
	
	echo $sqlCategory = "UPDATE software_user
								 SET 
							address					=	'$user_address',
							city					=	'$user_city',
							state					=	'$user_state',
							country					=	'$user_country',
							user_comments			=	'$user_comments',
							first_name				=	'$first_name',
							last_name				=	'$last_name',
							mobile					=	'$user_mobile',
							user_comments			=   '$user_comments'
						WHERE 
							id = '". $userId."'
							"; 	
							

 	if(mysql_query($sqlCategory))
	{
		header("location:trainer_profile_update.php?msg=1&user_id=". $userId);
	
	}
	else
		header("location:trainer_profile_update.php?msg=2&user_id=". $userId);
	exit();		
 }
 
  $sqlUser = mysql_query("SELECT * FROM software_user 
 										WHERE id = '".intval( $userId)."'");
  $resUser  = mysql_fetch_array($sqlUser);
  
  $sqlUserCourses = mysql_query("SELECT * FROM software_user_courses WHERE user_id = '".intval( $userId)."'");
  while($resUserCourses = mysql_fetch_array($sqlUserCourses)){
		$arrUserCourses[]	= $resUserCourses["user_course"];		  
  }


?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=TITLE_WEBSITE?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<center>
<div style="background:#179cc1; height:3px">&nbsp;</div>
<div style="width:990px;" align="center">
		<div id="header">
		<?php
    		include("includes/header.php");
   		?>
        </div>
    <div style="margin-top:20px;">
    	 <div style=" width:25%; float:left" >
        	 <?php include("includes/trainerLeftMenu.php");?>
        </div>
        <div style="width:75%;float:left">
        	<div style="margin-top:20px;">
    	<form id="form_login" name="form_login" method="post" onsubmit="return login_validation()" >
    	<?php
		$msg = $_REQUEST['msg'];
        if($msg != "")
		{
			if($msg == 1){
				$showMessage = 'You are registered successfully,please check your email address';
				$clsMessage = 'clsSuccess';	
			}else if($msg == 2){
				$showMessage = 'Sorry,Please check your email address again,as email address is already exist';
				$clsMessage = 'clsError';
			}else if($msg == 3){
				$showMessage = 'Sorry,Please check your email and password for login';
				$clsMessage = 'clsError';
			}
		?>
        <div align="left" class="<?=$clsMessage?>" style="margin-bottom:10px" >
           &nbsp; 	 <?=$showMessage?>
        </div>
        <?php
		}
		?>
        
        </form>
        <form id="form_register" name="form_register" method="post" onsubmit="return register_validation()" >
        <div style="width:85%; margin-left:40px" >
        	<div align="left" >
            	<span class="headingOrange" ><strong>Update your profile</strong></span>
            </div>
            <div class="text1"  align="left" style=" padding-top:18px;">
         		 <div  >	
                    <div style="float:left; width:30%" class="text" >Email:</div>
                    <div style="float:left; width:70%" ><input type="text" id="user_email" class="textBox" name="user_email" value="<?=$resUser["email"]?>" maxlength="30" disabled="disabled"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
                <div  style="margin-top:10px"  >	
                    <div style="float:left; width:30%" class="text" >User Type:</div>
                    <div style="float:left; width:70%" >
                    	<select id="user_type" name="user_type" class="textBox" disabled="disabled" >
                           <option value="Trainer" selected="selected"  >Trainer</option>
                        </select>
                    </div>
                    <div style=" clear:both" ></div>
                </div>
                <div  style="margin-top:10px" >	
                    <div style="float:left; width:30%" class="text" >Couses:</div>
                    <div style="float:left; width:70%" >
                    	<select id="user_course[]" name="user_course[]" multiple="multiple" class="multiSelect" disabled="disabled">
                        	<?php
                           	$sqlCourse = mysql_query("SELECT * FROM software_main_course where active = 'Y'");
							while($resCourse = mysql_fetch_array($sqlCourse )){
						   ?>
                           	<option value="<?php echo $resCourse["course_name"]?>" <?php
                                	if(!empty($arrUserCourses))
									{
										if(in_array($resCourse["course_name"],$arrUserCourses)){
											echo "selected=selected";	
										}else{
											echo "";	
										}
									}
								?>   ><?php echo $resCourse["course_name"]?></option>
                           
						   <?php			
							}
						   ?>
                        </select>
                    </div>
                    <div style=" clear:both" ></div>
                </div>
                <div style="margin-top:10px"  >	
                    <div style="float:left; width:30%" class="text" >First Name:</div>
                    <div style="float:left; width:70%" ><input onkeypress="return alphabetsOnly(this, event)" type="text" id="first_name" class="textBox" name="first_name" value="<?=$resUser["first_name"]?>"  maxlength="30" /> </div>
                    <div style=" clear:both" ></div>
                </div>
                <div  style="margin-top:10px" >	
                    <div style="float:left; width:30%" class="text" >Last Name:</div>
                    <div style="float:left; width:70%" ><input onkeypress="return alphabetsOnly(this, event)" type="text" id="last_name" class="textBox" name="last_name" value="<?=$resUser["last_name"]?>" maxlength="30"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
                 <div  style="margin-top:10px" >	
                    <div style="float:left; width:30%" class="text" >Mobile:</div>
                    <div style="float:left; width:70%" ><input onkeypress="return intOnly(this, event)" type="text" id="user_mobile" class="textBox" name="user_mobile" value="<?=$resUser["mobile"]?>"  maxlength="30" /> </div>
                    <div style=" clear:both" ></div>
                </div>
               
                <div  style="margin-top:10px" >	
                    <div style="float:left; width:30%" class="text" >Address:</div>
                    <div style="float:left; width:70%" ><input type="text" id="user_address" class="textBox" name="user_address" value="<?=$resUser["address"]?>"   maxlength="30"/> </div>
                    <div style=" clear:both" ></div>
                </div> 
                <div style="margin-top:10px"  >	
                    <div style="float:left; width:30%" class="text" >City:</div>
                    <div style="float:left; width:70%" ><input onkeypress="return alphabetsOnly(this, event)" type="text" id="user_city" class="textBox" name="user_city" value="<?=$resUser["city"]?>"  maxlength="30"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
                 <div style="margin-top:10px"  >	
                    <div style="float:left; width:30%" class="text" >State:</div>
                    <div style="float:left; width:70%" ><input onkeypress="return alphabetsOnly(this, event)" type="text" id="user_state" class="textBox" name="user_state" value="<?=$resUser["state"]?>"  maxlength="30"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
                
                 <div style="margin-top:10px" >	
                    <div style="float:left; width:30%" class="text" >Country:</div>
                    <div style="float:left; width:70%" ><select id="user_country" name="user_country" style="width:220px" class="textBox" >
                        	<option value="" >Select</option>
							<?php
                            	$sqlCountry = mysql_query("SELECT * FROM software_country WHERE status = 'Y'");
								while($resCountry = mysql_fetch_array($sqlCountry)){
							?>
                            <option value="<?php echo $resCountry["country_code"]; ?>" <?=($resUser["country"] == $resCountry["country_code"] ? 'selected=selected' : '')?> ><?php echo $resCountry["country_name"]; ?></option>
                            <?php
								}
							?>
                        </select>
                      </div>
                    <div style=" clear:both" ></div>
                </div>
                <div style="margin-top:10px" >	
                    <div style="float:left; width:30%" class="text" >User Comments:</div>
                    <div style="float:left; width:70%" >
                    	<input name="user_comments" id="user_comments" type="text" class="textBox" value="<?=$resUser['user_comments']?>" maxlength="70" />
                    </div>
                    <div style=" clear:both" ></div>
                </div>
                
                 <div style="margin-top:10px;" align="center">	
                 	<input type="hidden" id="action" name="action" value="Update"  />
                   	<input type="submit" class="button" name="submit" id="submit" value="Update your profile"  />
                </div>
                 
            </div>
        </div>
        </form>
      <div style="clear:both"></div>
    </div>
        	
        </div>
        <div style="clear:both"></div>
    </div>
    
    <div style="margin-top:23px; margin-bottom:21px" align="center" >
    	<?php
									$sqlAdvertise = mysql_query("SELECT * FROM software_advertise 
																	WHERE 
																		banner_status = 'Y' AND banner = 2
																		ORDER BY RAND()
																		");
									$resAdvertise = mysql_fetch_array($sqlAdvertise);
							
									$imgPath  = 'admin/upload_images/'.$resAdvertise["banner_image"];
									
								?>
								
    </div>
   </div>
   <div id="footer">
  		<?php include("includes/footer.php")?>
   </div>
</div>
	</div>
</center>
</body>
</html>
